package com.koala.learn.threadlearn.charter4;

/**
 * @Description 排队线程一个接着一个通知
 * @Date 2022/2/27 19:39
 * @Created by koala
 */

public class Start {

    public static void main(String[] args) throws InterruptedException {
        Thread previous = Thread.currentThread();
        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(new MyThread(previous), "线程" + i);
            thread.start();
            previous = thread;
        }

        System.out.println("main end");
    }


    static class MyThread implements Runnable {

        private final Thread thread;

        public MyThread(Thread thread) {
            this.thread = thread;
        }

        @Override
        public void run() {
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("I am " + Thread.currentThread().getName());
        }
    }
}
